package com.itxx.volatiles;
// volatile   解决
public class Test {
    public static void main(String[] args) {


        BoyThread b = new BoyThread();
        b.start();
        GirlThread g = new GirlThread();
        g.start();

    }
}

class BoyThread extends Thread {
    @Override
    public void run() {

            try {
                Thread.sleep(1);
                System.out.println("打游戏用了10000");
                Monkey.monkey = 90000;
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }


class GirlThread extends Thread {


    @Override
    public void run() {
        while (Monkey.monkey == 100000) {

        }
        System.out.println("gun");
    }
}

class Monkey {
    public static volatile int monkey=100000;

}

